﻿@using Shop.Entity;
@using Shop.Help;
@using Shop.Bll;
@using System.Data;
@using Shop.Help;
@using Webdiyer.WebControls.Mvc;
@{
    Layout = null;
    string serverPath = Safe.GetWebConfigValueByKey("ServerPath");

    DataTable replyTable = ViewData["Reply"] as DataTable;
}
@model  PagedList<DataRow>


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>列表</title>
    <link href="@Url.Content("/Content/admin/css/bootstrap.min.css")" rel="stylesheet" />
    <script src="/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Content/layer/layer.js"></script>
    @*<script src="~/Content/MvcPager/MvcPager.js"></script>*@
    <style>
        .glyphicon-star {
            color: #E0B92A;
            float: right;
        }

        blockquote {
            font-size: 14px;
        }

        .layui-layer-content {
            padding: 30px !important;
            padding-bottom: 0 !important;
            padding-top: 10px !important;
            background-color: #3595CC !important;
        }

        .layui-layer-TipsR {
            border-bottom-color: #3595CC !important;
        }

        .modal-footer {
            text-align: right;
        }

        .modal-sm {
            margin-bottom: 0;
        }

        .bg-danger {
            padding: 5px;
            font-size: 12px;
            margin-left: 20px;
            text-indent: 30px;
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <div class="portlet-body">
            <ol class="breadcrumb">
                <li><a href="/set/admin/center">首页></a></li>
                <li><a href="#">限时抢购></a></li>
                <li class="active">评论管理</li>
            </ol>
            <div style="display: flex;">
                <div class="navbar-form navbar-left" style="padding:0px;" role="search">
                    <button type="submit" class="btn btn-primary btn-sm " id="checkAll" onclick="CheckAll(this);">
                        <span class="glyphicon glyphicon-check" aria-hidden="true">全选</span>
                    </button>
                    <button type="submit" class="btn btn-primary btn-sm" onclick="Delete(null, '/cms/article/delete', '/cms/article/list/@(Model.CurrentPageIndex - 1 > 1 ? Model.CurrentPageIndex - 1 : 1)');">
                        <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;删除
                    </button>
                </div>

                <form class="navbar-form navbar-left" id="formSearch" role="form" method="post" action="/groupbuy/Comment/list">
                    <input type="hidden" name="PageSize" value="15" />

                    <div class="form-group">
                        <input type="text" class="form-control input-sm" id="SearchTitle" name="title" placeholder="请输入评论内容" />
                    </div>
                    <button type="submit" class="btn btn-primary btn-sm ">
                        <span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>&nbsp;搜索
                    </button>
                </form>
            </div>
            <br />
            <div id="divTable">

                @foreach (DataRow item in Model)
                {
                    <div class="media">
                        <div class="media-left">
                            <img class="media-object" alt="64x64" src="@item["HeadImg"]"
                                 onerror="this.src='/Content/img/people.png'" style="width: 50px; height: 50px;">
                            <p class="text-info text-center">@item["Name"]</p>
                        </div>

                        <div class="media-body">
                            <p class="text-primary" style="display:inline-block;">@item["Title"]</p>
                            <h5 style="display:inline-block;" class="text-right">
                                <small>订单号:[@item["OrderNumber"]]</small>
                            </h5>
                            @for (int i = 0; i < Convert.ToInt32(item["StartLevel"]); i++)
                            {
                                <span class="glyphicon glyphicon-star" aria-hidden="true"></span>
                            }
                            <blockquote>
                                <p class="content">@item["Content"]</p>
                                <footer>@Convert.ToDateTime(item["SubmitTime"]).ToString("yyyy-MM-dd HH:mm")<cite title="Source Title"></cite></footer>

                                @if (replyTable != null && replyTable.Select("parentGuid='" + item["Guid"] + "'").Count() > 0)
                                {
                                    <br />
                                    <div class='bg-danger'>
                                        <p class="text-success">@(replyTable.Select("parentGuid='" + item["Guid"] + "'")[0].Field<string>("Content")) </p>

                                        <p class="text-right">@(replyTable.Select("parentGuid='" + item["Guid"] + "'")[0].Field<DateTime>("SubmitTime").ToString("yyyy-MM-dd HH:mm"))</p>

                                    </div>
                                }
                                else
                                {
                                    <a id="@item["Guid"]" onclick="ShowReply('@item["Guid"]')" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                                        回复评论
                                    </a>
                                }

                            </blockquote>

                        </div>

                    </div>
                    <hr />
                }



                <div class="col-xs-9" style="width:auto;padding-left:0px;">
                    <ul class="pagination">
                        <li>
                            <span aria-hidden="true">
                                @(Model.PageSize)条/页，@(Model.TotalPageCount)页, 共@(Model.TotalItemCount)条
                            </span>
                        </li>
                        <li>
                            <span aria-hidden="true">
                                每页
                                <select style="border-radius:4px;font-size:smaller;vertical-align: text-bottom;" id="PageSize" name="PageSize" onchange="PageSizeChange();">
                                    <option value="10">10</option>
                                    <option selected="selected" value="15">15</option>
                                    <option value="20">20</option>
                                </select>
                                条
                            </span>
                        </li>
                    </ul>
                    @Ajax.Pager(Model,
                new PagerOptions
                {
                    PageIndexParameterName = "pageIndex",
                    CssClass = "pagination",
                    FirstPageText = "首页",
                    LastPageText = "尾页",
                    PrevPageText = "上一页",
                    PageIndexBoxId = "pageIndexBox",
                    GoToButtonId = "Go",
                    PageIndexOutOfRangeErrorMessage = "页码有误!",
                    NumericPagerItemCount = 8,
                    NextPageText = "下一页",
                    CurrentPagerItemTemplate = "<li class=\"active\"><a data-pageindex=\"{0}\" href=\"/GroupBuy/Comment/List/{0}\">{0}</a></li>",
                    DisabledPagerItemTemplate = "<li class=\"disabled\"><a>{0}</a></li>",
                    PagerItemTemplate = "<li>{0}</li>",
                    AutoHide = false,

                }, new MvcAjaxOptions
                {
                    UpdateTargetId = "divTable",
                    HttpMethod = "Post",
                    DataFormId = "formSearch",
                    EnableHistorySupport = false,
                    OnSuccess = "Success();",
                    EnablePartialLoading = true
                }
                )
                </div>
                <div class="pagination" style="width:20%;margin-top: 0px;">
                    <ul class="pagination">
                        <li>
                            <div class="input-group">
                                <span class="input-group-addon">第</span>
                                <input type="text" id="pageIndexBox" class="form-control input-sm" placeholder="" aria-describedby="sizing-addon2" oninput="InputPageIndex(this);">
                                <span class="input-group-addon">页</span>
                                <span class="input-group-btn">
                                    <button class="btn btn-primary btn-sm" id="Go" type="button">Go</button>
                                </span>
                            </div>
                        </li>
                    </ul>
                </div>

                <script type="text/javascript">
                    $('.collapse').collapse()
                function Success()
                {
                    var txt = $("#SearchTitle").val().trim();
                    if (txt.length > 0)
                    {
                        $(".content").each(function ()
                        {
                            var newTxt = $(this).html().replace(txt, txt.fontcolor("red"));
                            $(this).html(newTxt);
                        });
                    }

                    $("input[name='PageSize']").val('@ViewData["NowPageSize"]');
                    $("#PageSize").val(@ViewData["NowPageSize"]);
                    }

                </script>

            </div>
        </div>
    </div>


    @{Html.RegisterMvcPagerScriptResource();}
    <script src="/Content/LwsJS/List.js"></script>
    <script type="text/javascript">

                function PageSizeChange() {
                    $("input[name='PageSize']").val($("#PageSize").val());

                    $("#formSearch").submit();
                }
                function InputPageIndex(obj) {
                    var pageIndex = $(obj).val().trim();
                    if (parseInt(pageIndex) > parseInt($("#TotalPageCount").val())) {
                        $(obj).val($("#TotalPageCount").val());
                    }
                }
                function GoPageIndex() {
                    var pager = Webdiyer.MvcPagers[0];
                    var pageIndex = $("#pageIndexBox").val().trim();
                    var TotalPageCount = $("#TotalPageCount").val().trim();
                    if (parseInt(pageIndex) > parseInt(TotalPageCount)) {
                        pageIndex = TotalPageCount;
                    }
                    if (pager != null) {
                        pager.goToPage(parseInt(pageIndex));
                    } else
                    { alert("找不到指定的MvcPager！"); }
                }

                function ShowReply(guid) {

                    var html = " <div class='modal-dialog modal-sm' role='document'>\
                        <div class='modal-content'>\
 <textarea class='form-control' rows='3'></textarea>\
    </div>\
 <div class='modal-footer'>\
<button type='button' class='btn btn-success btn-xs' onclick=\"Reply('"+ guid + "');\">确认回复</button>\
      </div >\
    </div>";
                    layer.open({
                        type: 4,
                        shadeClose: true,
                        skin: 'reply',
                        closeBtn: 1,
                        title: '回复',
                        content: [html, '#' + guid], //数组第二项即吸附元素选择器或者DOM
                    });
                }

                function Reply(guid) {

                    if ($(".modal-content").find("textarea").val().trim().length == 0) {
                        $(".modal-content").find("textarea").focus(); return;
                    }
                    var content = $(".modal-content").find("textarea").val().trim();
                    $.post(
                        "/groupbuy/comment/reply",
                        { guid: guid, content: content },
                        function (data) {
                            if (data.succ) {
                                layer.closeAll('tips'); //关闭所有的tips层
                                //var ht = "<div style='display:none;' class='bg-danger'>\
                                //    <p>"+ content + "</p>\
                                //</div>";
                                //$("#" + guid).after(ht).siblings(".bg-danger").fadeIn(500);
                                //$("#" + guid).remove();
                                $(".pagination .active").find("a").click();
                            } else {
                                layer.msg('评论回复失败!');
                            }
                        }

                    );

                }
    </script>
</body>
</html>